package com.dykj.fireFighting.web.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import com.dykj.fireFighting.api.elasticsearch.devHisWater.entity.EsDevHisWater;
import com.dykj.fireFighting.api.elasticsearch.devHisWater.service.EsDevHisWaterService;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.model.report.DevHisWater;
import com.dykj.fireFighting.web.rocketmq.message.InsertDevHisMessage;
import com.dykj.fireFighting.web.rocketmq.message.InsertDevHisWaterMessage;
import com.dykj.fireFighting.web.service.DevHisService;
import com.dykj.fireFighting.web.utils.SpringUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

/**
 * @author zhengbo
 */
//@RocketMQMessageListener(
//        topic = InsertDevHisWaterMessage.TOPIC,
//        consumerGroup = "dy-consumer-group-" + InsertDevHisWaterMessage.TOPIC
//)
public class InsertDevHisWaterConsumer implements RocketMQListener<InsertDevHisWaterMessage> {
    public static final Logger LOGGER = LoggerFactory.getLogger(InsertDevHisWaterConsumer.class);
    private static final RedisService redisService= SpringUtil.getBean(RedisService.class);
    private static final DevHisService devHisService= SpringUtil.getBean(DevHisService.class);
    private static final EsDevHisWaterService esDevHisWaterService= SpringUtil.getBean("esDevHisWaterService");
    @Override
    public void onMessage(InsertDevHisWaterMessage insertDevHisWaterMessage) {
//        DevHisWater devHisWater = insertDevHisWaterMessage.getDevHisWater();
//        LOGGER.info("===========插入EsDevHisWater数据到mysql==============");
//        devHisService.insertDevHisWater(devHisWater);
//        LOGGER.info("===========插入EsDevHisWater数据到ES==============");
//        EsDevHisWater esDevHisWater = new EsDevHisWater();
//        BeanUtils.copyProperties(devHisWater, esDevHisWater);
//        esDevHisWater.setUnitId(devHisWater.getUnitId());
//        esDevHisWater.setDeviceName(devHisWater.getDeviceName());
//        esDevHisWater.setUniqueCode(devHisWater.getDevId());
//        System.out.println("===="+esDevHisWater.getId());
//        esDevHisWaterService.importAll(esDevHisWater);
//        LOGGER.info("===========插入EsDevHisWater数据到ES:=============" + JSON.toJSONString(esDevHisWater));
//        redisService.set(devHisWater.getId(), JSON.toJSONString(devHisWater), 3600L);
    }
}
